package com.itheima.mybatis_plus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mybatis_plus.dao.CourseDao;
import com.itheima.mybatis_plus.pojo.Course;
import com.itheima.mybatis_plus.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2021/10/9 9:03
 * @description
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseDao,Course> implements CourseService {
    @Autowired
    private CourseDao courseDao;
    @Override
    public List<Course> findAll() {
        return courseDao.selectList(null);
    }

    @Override
    public Course findById(int id) {
        return courseDao.findById(id);
    }

    @Override
    public void add(Course course) {
        courseDao.insert(course);
    }

    @Override
    public void update(Course course) {
        courseDao.updateById(course);
    }

    @Override
    public void deleteById(int id) {
        courseDao.deleteById(id);
    }

    @Override
    public Page<Course> page1(int pageNumber, int pageSize) {
        Page<Course> page=new Page<>(pageNumber,pageSize);
        Page<Course> selectPage = courseDao.selectPage(page, null);


        //


        return selectPage;

    }

    @Override
    public List findByCondition(String name, Integer userId) {
        //QueryWrapper queryWrapper=new QueryWrapper();

        //queryWrapper.eq("name",name);

        //queryWrapper.like("name",name);
        //queryWrapper.likeLeft("name",name);
        //queryWrapper.likeRight("name",name);

        //queryWrapper.like("name",name);
        //queryWrapper.eq("user_id",userId);

        //queryWrapper.or(true).eq("user_id",userId);

        LambdaQueryWrapper<Course> lambdaQueryWrapper = new LambdaQueryWrapper();
        //queryWrapper.eq("name",name);
        lambdaQueryWrapper.eq(Course::getName,name);





        //select * from tb_course where name=?
        return courseDao.selectList(lambdaQueryWrapper);

    }
}
